<?php
class ml_biz_attitude 
{

    static $err_msg = array (
                                'noExist' => 'content not exist',
                                'fail' =>'server busy',
                                'liked' =>'content has been liked',
    );
    
    private $err = '';
    private $_content_tag;
    
    //此时的oid  可能是宝贝主人，也可能不是
    public function addAttitude($aid, $rid, $oid, $att, $from = 1, $time =null){
        
         $oContent = new ml_model_dbContent();
         $rs = $oContent->get_by_rid($rid);
         if (!$rs) {
             $this->err = self::$err_msg['noExist'];
             return false;
         }
         
         $aContent = $oContent->get_data();
         $this->_content_tag = $aContent['gd_info']['tags'];
         
         $likeme = new ml_model_dbLikeMe();
         $ilike = new ml_model_dbILike();

         $rs = $ilike->isIAttByRid($aid, $rid, $isExist);
         if (!$rs) {
             $this->err = self::$err_msg['fail'];
             return false;
         }
         
         if ($isExist) {
             $this->err = self::$err_msg['liked'];
             return false;
         }
         //喜欢某个人的喜欢，双发操作  
         $owner_uid =ml_tool_resid::resid2uid($rid);
         
         if ($ilike->createLike($aid, $rid, $oid, $att, $from, $time)) {
             
             $likeme->createLike($oid, $rid, $aid, $att, $from, $time);
             
             //如果不是宝贝主人，说明喜欢被转发，oid即为中间人
             if($owner_uid != $oid ){
                 $likeme->createLike($owner_uid, $rid, $aid, $att, $from, $time);
             }
             
         } else {
             $this->err = self::$err_msg['fail'];
             return false;
         }
         
         
         /**
          * @todo
          * 扔统计队列
          * 扔检查队列
          */
         
         
         return true;
    }
    public function get_content_tags()
    {
        return $this->_content_tag;
    }
    public function get_errinfo () {
        return $this->err;
    }
    

}
